package com.chris.conference;

import com.chris.conference.Class.Record;
import com.chris.conference.Class.SimpleRecord;
import com.chris.conference.Repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class SimpleRecordSearch {

    @Autowired
    private UserRepository userRepository;

    public SimpleRecordSearch(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    public List<SimpleRecord> simpleRecordFindByWeek(List<Record> recordList){
        List<SimpleRecord> simpleRecordList= new ArrayList<>();
        for (int i = 0;i < recordList.size(); i ++){
            Record record = recordList.get(i);
            SimpleRecord simpleRecord = new SimpleRecord(record);
            simpleRecord.setUsername(userRepository.findByUserid(record.getUserid()).getUsername());
            simpleRecordList.add(simpleRecord);
        }
        return simpleRecordList;
    }
}
